# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib.auth.models import User
from django.db import models


# Create your models here.
class Topic(models.Model):

    """用户学习的主题"""
    text = models.CharField(max_length=200)  # 学习的主题，如编程语言
    date_append = models.DateTimeField(auto_now_add=True)  # 创建主题的时间
    owner = models.ForeignKey(User)

    """返回模型的字符串表示"""

    def __unicode__(self):
        return self.text


class Entry(models.Model):
    topic = models.ForeignKey(Topic, on_delete=models.CASCADE)
    text = models.TextField()
    date_added = models.DateTimeField(auto_now_add=True)

    class Meta:
        verbose_name_plural = 'entries'

    def __unicode__(self):
        return self.text[:50] + '...'
